package com.itheima.jianbing2;

public class Foodie implements Runnable {

    private Desk desk;

    public Foodie(Desk desk) {
        this.desk = desk;
    }

    @Override
    public void run() {
        //死循环  可劲在这吃  到数了 就不吃了
        while (desk.getCount() > 0) {
            synchronized (desk.getObj()) {
                //判断是否有
                if (desk.isFlag()) {
                    //有  吃
                    System.out.println(Thread.currentThread().getName()+"正在吃煎饼...吃完了");
                    //改状态
                    desk.setFlag(false);
                    desk.setCount(desk.getCount() - 1);
                    //叫大爷继续做
                    desk.getObj().notifyAll();
                } else {//没有  等着
                    try {
                        desk.getObj().wait();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }


        }


    }
}
